-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
movies-list-add-form #2085
base: master
Are you sure you want to change the base?
movies-list-add-form #2085
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something wrong with your link, feel free to ask for some help with that in the chat
src/components/NewMovie/NewMovie.tsx
Outdated
const [title, setTitle] = useState(''); | ||
const [description, setDescription] = useState(''); | ||
const [imgUrl, setImgUrl] = useState(''); | ||
const [imdbUrl, setImdbUrl] = useState(''); | ||
const [imdbId, setImdbId] = useState(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can combine it in one useState
const [newMovie, setNewMovie] = useState({
title: '',
...
})
now we can also create only one handle function for all fields
const handleChange = (e: ...) => {
const {name, value} = e.target;
setMovie((prevMovie) => ({...prevMovie, [name]: value}))
}
don't forget to specify name attr to input in TextField
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
demo link doesn't work, try to rerun "npm run deploy" command or ask for help in fe_chat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work, but lets make some improvement
form works strange, errors appear in different places and dont added new film after submit
https://www.loom.com/share/ef26224b8df14f3a8dcbd0ec67dbb511
|
||
export const NewMovie: React.FC<Props> = ({ onAdd }) => { | ||
const [count, setCount] = useState(0); | ||
|
||
const [newMovie, setNewMovie] = useState({ | ||
title: '', | ||
description: '', | ||
imgUrl: '', | ||
imdbUrl: '', | ||
imdbId: '', | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move an initial state to a variable
export const NewMovie: React.FC<Props> = ({ onAdd }) => { | |
const [count, setCount] = useState(0); | |
const [newMovie, setNewMovie] = useState({ | |
title: '', | |
description: '', | |
imgUrl: '', | |
imdbUrl: '', | |
imdbId: '', | |
}); | |
const initialMovieState = { | |
title: '', | |
description: '', | |
imgUrl: '', | |
imdbUrl: '', | |
imdbId: '', | |
} | |
export const NewMovie: React.FC<Props> = ({ onAdd }) => { | |
const [count, setCount] = useState(0); | |
const [newMovie, setNewMovie] = useState(initialMovieState); |
setNewMovie({ | ||
title: '', | ||
description: '', | ||
imgUrl: '', | ||
imdbUrl: '', | ||
imdbId: '', | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setNewMovie({ | |
title: '', | |
description: '', | |
imgUrl: '', | |
imdbUrl: '', | |
imdbId: '', | |
}); | |
setNewMovie(initialMovieState); |
DEMO LINK